package com.glory.dmegcpda.model

import android.util.Log
import com.glory.dmegcpda.base.Constant
import com.glory.dmegcpda.bean.BaseRequestBean
import com.glory.dmegcpda.bean.HeaderBean
import com.glory.dmegcpda.bean.NetRequestBean
import com.glory.dmegcpda.utils.TrimUtils
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils
import org.apache.commons.lang3.StringEscapeUtils

/**
 * @author HX
 * @date 2021/4/21
 * @desc
 */
open class BaseRepository {
    protected fun getInJsonData(bodyMap: JsonObject,messageName : String): Map<String,String> {
        val format: NetRequestBean<*> = NetRequestBean<Any>()
        format.body =bodyMap
        format.header = HeaderBean(messageName, Constant.userName,Constant.orgName,Constant.orgrrn)
        val message: BaseRequestBean<*> = BaseRequestBean<Any>()
        message.request = format
        val map = hashMapOf<String,String>()
        val unescapeJson = StringEscapeUtils.unescapeJson(Gson().toJson(message))
        val replace = unescapeJson.replace("\\", "")
        val replace1 = replace.replace(" ", "")
        map["requestMessage"] = TrimUtils.trimnull(replace1)
        map["senderId"] = "DMEGCSender"
        FreeApi_LogUtils.saveErrorMessages(map.toString(), "请求json")
        Log.e("请求json", "getInJsonData: $map")
        return map
    }

    protected fun getInJsonDataForPms(bodyMap: JsonObject,messageName : String): Map<String,String> {
        val format: NetRequestBean<*> = NetRequestBean<Any>()
        format.body =bodyMap
        format.header = HeaderBean(messageName, Constant.userName,Constant.orgName,Constant.orgrrn)
        val message: BaseRequestBean<*> = BaseRequestBean<Any>()
        message.request = format
        val map = hashMapOf<String,String>()
        map["requestMessage"] = StringEscapeUtils.unescapeJson(Gson().toJson(message))
        map["senderId"] = "PMSSender"
        FreeApi_LogUtils.saveErrorMessages(map.toString(), "请求json")
        Log.e("请求json", "getInJsonData: $map")
        return map
    }

}